package com.dq.domain.sys.user.user.centre;

import com.dq.domain.base.BaseEntity;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import com.dq.vo.baseVo.VO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

/**
 * @author cf
 */
@Data
@Entity
@ApiModel("用户标签与用户关联表")
public class UserLableCentre extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("标签所属对象")
    @ManyToOne
    protected SysUser sysUser;

    @ApiModelProperty("用户标签对象")
    @ManyToOne
    protected UserLable userLable;

    @ApiModelProperty("次数")
    @NotNull
    protected Integer lableCount;


    public UserLableCentre() {
    }
    public UserLableCentre(SysUser sysUser, UserLable userLable, int lableCount) {
        this.sysUser = sysUser;
        this.userLable = userLable;
        this.lableCount = lableCount;
    }

    @Data
    @ApiModel(value = "视图")
    public static class Vo implements VO {
        protected Long id;

        @ApiModelProperty(value = "标签所属对象")
        private Long sysUserId;
        private String sysUserName;
        @ApiModelProperty(value = "用户标签")
        private Long userLableId;
        private String userLableName;
        @ApiModelProperty("次数")
        protected int lableCount;

        @ApiModelProperty(value = "创建时间")
        private String createTime;
    }  @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.sysUserId = this.getSysUser() == null ? null : this.getSysUser().getId();
        vo.sysUserName = this.getSysUser() == null ? "" : this.getSysUser().getUserRealcName();
        vo.userLableId = this.getUserLable() == null ? null : this.getUserLable().getId();
        vo.userLableName = this.getUserLable() == null ? "" : this.getUserLable().getName();

        vo.createTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);

        return vo;
    }
}
